/**
 *  This file is part of AugeasWH.
 *
 *  AugeasWH. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AugeasWH. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AugeasWH.  If not, see <http://www.gnu.org/licenses/>.
 */

package cz.fit.vutbr.pis2012.augeaswh.control.administration.user;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import java.io.Serializable;
import java.util.List;

import cz.fit.vutbr.pis2012.augeaswh.managers.UserManager;
import cz.fit.vutbr.pis2012.augeaswh.persistence.User;

@ManagedBean
@ViewScoped
public class UsersBean implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@EJB
	private transient UserManager userManager;
	private int page;
	private int rowsPerPage;
	private User selectedUser;
	private List<User> users;
	
	public UsersBean() {
		page = 1;
		rowsPerPage = 15;
		selectedUser = null;
	}
	
	public List<User> getAllUsers() {
		users = userManager.getAllUsers();
		return users;
	}
	
	public void deleteUser() {
		if (selectedUser != null)
			userManager.deleteUser(selectedUser);
		System.out.println(selectedUser);
	}
	
	public void setPage(int page) {
		this.page = page;
	}
	
	public int getPage() {
		return page;
	}
	
	public void setSelectedUser(User user) {
		this.selectedUser = user;
	}
	
	public User getSelectedUser() {
		return selectedUser;
	}
	
	public int getRowsPerPage() {
		return rowsPerPage;
	}
	
	public boolean isPager() {
		return users != null && users.size() > rowsPerPage;
	}
}
